import os
import flask
from flask import Flask
from flask import request
from flask import jsonify

app = Flask(__name__)

root_path = os.path.dirname(os.path.abspath(__file__))
save_path = os.path.join(root_path,'data')

@app.route("/",methods=["GET"])
def index():
    return "<H1>hello web</H1>"

@app.route('/upload', methods=['GET', 'POST'])
def upload_file():
    if request.method == 'POST':
        mesg = {}
        try:
            f = request.files['image']
            print(f.filename)
            save_file = os.path.join(save_path,f.filename)
            f.save(save_file)
            mesg['mesg'] = "succed"
        except:
            mesg['mesg'] = "failed"

    return jsonify(mesg)

if __name__ == "__main__":
    app.run(host="0.0.0.0",debug=True)
